package com.java.mybatis.service.impl;

import com.java.mybatis.dao.LeavewarehouseDao;
import com.java.mybatis.entity.Leavewarehouse;
import com.java.mybatis.service.LeavewarehouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Leavewarehouse)表服务实现类
 *
 * @author makejava
 * @since 2021-01-15 17:10:28
 */
@Service("leavewarehouseService")
public class LeavewarehouseServiceImpl implements LeavewarehouseService {
    @Resource
    private LeavewarehouseDao leavewarehouseDao;

    /**
     * 通过ID查询单条数据
     *
     * @param leavewarehouseId 主键
     * @return 实例对象
     */
    @Override
    public Leavewarehouse queryById(Integer leavewarehouseId) {
        return this.leavewarehouseDao.queryById(leavewarehouseId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Leavewarehouse> queryAllByLimit(int offset, int limit) {
        return this.leavewarehouseDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param leavewarehouse 实例对象
     * @return 实例对象
     */
    @Override
    public Leavewarehouse insert(Leavewarehouse leavewarehouse) {
        this.leavewarehouseDao.insert(leavewarehouse);
        return leavewarehouse;
    }

    /**
     * 修改数据
     *
     * @param leavewarehouse 实例对象
     * @return 实例对象
     */
    @Override
    public Leavewarehouse update(Leavewarehouse leavewarehouse) {
        this.leavewarehouseDao.update(leavewarehouse);
        return this.queryById(leavewarehouse.getLeavewarehouseId());
    }

    /**
     * 通过主键删除数据
     *
     * @param leavewarehouseId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer leavewarehouseId) {
        return this.leavewarehouseDao.deleteById(leavewarehouseId) > 0;
    }

    /**
     * 添加出库记录
     * @param leavewarehouse
     * @return
     */
    @Override
    public int insertLeavewarehouse(Leavewarehouse leavewarehouse){
        return leavewarehouseDao.insertLeavewarehouse(leavewarehouse);
    }

    /**
     * 查询最大id
     */
    @Override
    public int queryByIdMax(){
        return leavewarehouseDao.queryByIdMax();
    }
}